package digimon.organism;

public class BodyOrganism {
	/**
	 * Quantity of elements in X direction of body
	 */
	public int BODY_SIZE_X;
	
	/**
	 * Quantity of elements in Y direction of body
	 */
	public int BODY_SIZE_Y;
	
	/**
	 * A matrix that contain the organisms in body
	 */
	private Organism[][] bodyCells;
	
	/**
	 * The values if the body is looking to the desired direction
	 */
	public static int DIR_NORTH = 0;
	public static int DIR_SOUTH = 1;
	public static int DIR_EAST = 2;
	public static int DIR_WEST = 3;
	
	/**
	 * The orientation variable
	 */
	private int orientation;
	
	/**
	 * A variable to set the total energy of the entire organism
	 * Some instructions waste energy 
	 */
	private int energy;
	
	/**
	 * The default constructor
	 */
	public BodyOrganism(int x, int y) {
		// Set the body
		BODY_SIZE_X = x;
		BODY_SIZE_Y = y;
		
		setBodyCells(new Organism[BODY_SIZE_X][BODY_SIZE_Y]);
		
		// Generate initial energy
		setEnergy(1000);
		
		// Put the body looking to North
		setOrientation(DIR_NORTH);
		
		
		// put dunno organism into corners
		bodyCells[0][0] = new Organism();
		bodyCells[0][BODY_SIZE_Y-1] = new Organism();
		bodyCells[BODY_SIZE_X-1][0] = new Organism();
		bodyCells[BODY_SIZE_X-1][BODY_SIZE_Y-1] = new Organism();
		
		
		// Put the Vision Organisms
		for(int range = 1; range < BODY_SIZE_X-1; range ++){
			bodyCells[0][range] = new Vision();
		}
		
		// Put the Comunication organisms
		for(int range = 1; range < BODY_SIZE_X-1; range ++){
			for(int range2 = 1; range2 < BODY_SIZE_Y - 1; range2++)
				bodyCells[range][range2] = new Communicator();
		}
		
		for(int range = 1; range < BODY_SIZE_X; range ++)
			bodyCells[range][0] = new Motor();
		for(int range = 1; range < BODY_SIZE_X; range ++)
			bodyCells[range][BODY_SIZE_X-1] = new Motor();
		for(int range = 1; range < BODY_SIZE_X-1; range ++){
			bodyCells[BODY_SIZE_Y-1][range] = new Motor();
		}
	}

	public int getOrientation() {
		return orientation;
	}

	public void setOrientation(int orientation) {
		this.orientation = orientation;
	}

	public int getEnergy() {
		return energy;
	}

	public void setEnergy(int energy) {
		this.energy = energy;
	}

	/**
	 * @return the bodyCells
	 */
	public Organism[][] getBodyCells() {
		return bodyCells;
	}

	/**
	 * @param bodyCells the bodyCells to set
	 */
	public void setBodyCells(Organism[][] bodyCells) {
		this.bodyCells = bodyCells;
	}
}
